package com.example.rabbitmqdemo.workQueues;

import com.example.rabbitmqdemo.utils.RabbitMQUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author：DijaH
 * @Date：2023/12/6 15:39
 * @Version：1.0.0
 * @Description： 轮询消费
 *
 * 创建两个工作队列
 */
public class Work01 {

    public static final String QUEUE_NAME = "hello";

    //接收消息
    public static void main(String [] args) throws IOException, TimeoutException{
        Channel channel = RabbitMQUtils.getChannel();
        //消息的接收
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息："+new String(message.getBody()));
        };

        //消息接收被取消时，执行下面的内容
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println(consumerTag + "：消息被消费者取消消费接口回掉逻辑");
        };

        //消息的接收
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);

        System.out.println(1);
    }
}
